package com.easy.facilitaterecycleadapter.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.TextView;

import com.easy.facilitaterecycleadapter.R;

/**
 * Created by Sigthp-P-Department on 2018/5/9.
 */

public class DefaultLoaderCreator extends LoaderViewCreator{
    private View mLoaderIv;
    private TextView mLoaderTv;
    @Override
    public View getLoadView(Context context, ViewGroup parent) {
        View refreshView = LayoutInflater.from(context).inflate(R.layout.layout_loader_footer_view, parent, false);
        mLoaderIv = refreshView.findViewById(R.id.refresh_iv);
        mLoaderTv = refreshView.findViewById(R.id.refresh_tv);
        return refreshView;
    }

    @Override
    public void onPullLoader(int currentDragHeight, int loadViewHeight, int currentLoadStatus) {
        if(RefreshAndLoaderRecyclerView.LOAD_STATUS_LOOSEN_LOADING == currentLoadStatus){
            mLoaderTv.setText("松手刷新...");
        }
    }

    @Override
    public void onLoaderLoading() {
        mLoaderTv.setVisibility(View.INVISIBLE);
        mLoaderIv.setVisibility(View.VISIBLE);
        RotateAnimation animation = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        animation.setRepeatCount(-1);
        animation.setDuration(1000);
        mLoaderIv.startAnimation(animation);
    }

    @Override
    public void onLoaderStop() {
        mLoaderTv.setVisibility(View.VISIBLE);
        mLoaderIv.setVisibility(View.GONE);
        mLoaderTv.setText("下拉加载...");
        mLoaderIv.setRotation(0);
        mLoaderIv.clearAnimation();
    }


}
